#!/usr/bin/python3
# _*_ coding: utf-8 _*_
#
# Copyright (C) 2024 - 2024 heihieyouheihei, Inc. All Rights Reserved 
#
# @Time    : 2024/9/19 20:06
# @Author  : Yuyun
# @File    : 链表的基本操作.py
# @IDE     : PyCharm

class ListNode:
    #   链表节点
    def __init__(self,val = 0,next = None):
        self.val = val
        self.next = next
class LinkList:
    #   链表初始化，初始不传入num_list或者num_list为空时，只初始化虚拟头节点，后续插入在虚拟头节点上进行操作
    def __init__(self,num_list = []):
        self.dummy_head = ListNode()
        self.size = len(num_list)
        current = self.dummy_head
        # 实现逆序存储，方便输出时逆序输出
        for num in num_list[::-1]:
            node = ListNode(num)
            current.next = node
            current = current.next
    def show_linklist(self):
        current = self.dummy_head.next
        if not current:
            print("Link list is empty")
            return
        else:
            while current != None:
                print(current.val, end=' ')
                current = current.next
            #   输出格式，必须换行
            print()
    def insert(self, index, num):
        current = self.dummy_head
        #   插入节点可位于头节点(index = 1)、中间节点(1< index <=size)、尾节点（index = size + 1）
        if index <= 0 or index > self.size + 1:
            print('insert fail')
            return
        #   currrent指向虚拟头节点，index表示从1开始下标，遍历元素i从1开始便可直接照顾到头节点前插入
        for i in range(1, index):
            current = current.next
        new_node = ListNode(num)
        new_node.next = current.next
        current.next = new_node
        self.size += 1
        print('insert OK')
    def get(self, index):
        current = self.dummy_head
        #   链表空或者index越界Fail
        if index <= 0 or index > self.size or current.next == None:
            print('get fail')
            return
        for i in range(index):
            current = current.next
        num = current.val
        print(num)
    def delete(self, index):
        current = self.dummy_head
        #   链表空或者index越界Fail
        if index <= 0 or index > self.size or current.next == None:
            print('delete fail')
            return
        #   currrent指向虚拟头节点，index表示从1开始下标，遍历元素i从1开始便可直接照顾到删除头节点
        for i in range(1, index):
            current = current.next
        current.next = current.next.next
        self.size -= 1
        print('delete OK')
class Solution:
    #   处理操作
    def deal_with_operations(self, linklist:LinkList, operations, n):
        for i in range(n):
            if operations[i][0] == 'show':
                linklist.show_linklist()
            elif operations[i][0] == 'get':
                linklist.get(int(operations[i][1]))
            elif operations[i][0] == 'insert':
                linklist.insert(int(operations[i][1]),int(operations[i][2]))
            elif operations[i][0] == 'delete':
                linklist.delete(int(operations[i][1]))
            else:
                raise Exception('input error')

if __name__ == '__main__':
    try:
        nums_in = list(map(int, input().split()))
        if nums_in[0] != len(nums_in) - 1:
            raise Exception('input error')
        linklist = LinkList(nums_in[1:])
        n = int(input())
        #   存储操作
        operations = []
        for _ in range(n):
            operation = input().split()
            operations.append(operation)
        solution = Solution()
        solution.deal_with_operations(linklist, operations, n)
    except Exception as e:
        print(e)